{% extends 'myadmin/base.html' %}

{% block main_body %}
<div style="height:60px">

</div>
 <div class="card-header">
     <h3 class="card-title"><a href="{% url 'myadmin_index' %}">首页</a> >> <a href="{% url 'myadmin_flavor_index' %}">实例类型管理</a> >> 实例类型编辑</h3>
 </div>
<div style="width:70%; margin-left:15%;">
 <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">实例类型编辑</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <form action="{% url 'myadmin_flavor_update' %}" method="post">
                  {% csrf_token %}
                <div class="card-body">
                  <div class="form-group">
                      <label for="flavorname">实例类型名称<font color="red">*</font></label>
                      <p><font color="red"><b>{{ flavor.name }}</b></font> </p>
                    <input type="hidden" name="flavorid" value="{{ flavor.id }}" />
                      <input type="hidden" name="flavorname" value="{{ flavor.name }}" />
                  </div>
                  <div class="form-group">
                    <label for="vcpus">vcpu数量<font color="red">*</font></label>
                    <input type="text" class="form-control" id="vcpus" name="vcpus" placeholder="请输入vcpu数量" value="{{ flavor.vcpus }}" disabled="false">
                  </div>
                    <div class="form-group">
                    <label for="ram">内存(MB)<font color="red">*</font></label>
                    <input type="text" class="form-control" id="ram" name="ram"  placeholder="请输入内存数量" value="{{ flavor.ram }}" disabled="false">
                  </div>
                    <div class="form-group">
                    <label for="disk">根磁盘(GB)<font color="red">*</font></label>
                    <input type="text" class="form-control" id="disk" name="disk" placeholder="请输入根磁盘大小" value="{{ flavor.disk }}" disabled="false">
                  </div>
                     <div class="form-group">
                    <label for="swap">SWAP磁盘(MB)</label>
                          {%  if flavor.swap == "" %}
                                <input type="text" class="form-control" name="swap" id="swap" placeholder="请输入SWAP磁盘大小"  value="0" disabled="false">
                          {% else %}

                          <input type="text" class="form-control" name="swap" id="swap" placeholder="请输入SWAP磁盘大小"  value="{{ flavor.swap }}" disabled="false">
                            {% endif %}
                  </div>
                     <div class="form-group">
                    <label for="vcpus">描述<font color="red"></font></label>
                    <input type="text" class="form-control" id="description" name="description" placeholder="请输入描述信息数量" value="{{ flavor.description }}">
                  </div>



                </div>
                <!-- /.card-body -->

                <div class="card-footer">
                  <button type="submit" class="btn btn-primary" onclick="return check();">修改</button>
                    &nbsp; &nbsp;
                    <button type="reset" class="btn btn-primary">重置</button>
                </div>
              </form>
            </div>
</div>
<script>
    function check(){
         //flavorname = document.getElementById('flavorname').value;
         vcpus = document.getElementById('vcpus').value;
         disk = document.getElementById('disk').value;
         ram = document.getElementById('ram').value;
         swap = document.getElementById('swap').value;
         info="";

         //if(flavorname==""){
         //   info="实例类型名称不能为空！！\n"
        // }

         if(vcpus==""){
            info=info+"vcpu数量不能为空！！\n"
         }
         else if(isNaN(vcpus)){
             info=info+"vcpu数量不是数字！！\n"
         }

         if(ram==""){
            info=info+"内存不能为空！！\n"
         }
         else if(isNaN(ram)){
             info=info+"内存不是数字！！\n"
         }
         if(disk==""){
            info=info+"根磁盘不能为空！！\n"
         }
         else if(isNaN(disk)){
             info=info+"根磁盘不是数字！！\n"
         }

         if(disk!=""&&isNaN(disk)){
             info=info+"swap不是数字！！\n"
         }

         if(info!=""){
            alert(info);
            return false;
         }


         return true;

    }
</script>

{% endblock %}